home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Folder Watching / FW Receiver ƒ / Sources / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  2.9 KB  |  181 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Events.c
  3.  
  4.     Contains:    Main event loop and basic keyboard/mouse processing
  5.  
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.             26/01/96            GS        FW Receiver
  13.                                         Added call to remove Notification when suspend or
  14.                                         resume event received.
  15.  
  16.             12/18/95            CW        First release
  17.  
  18. */
  19.  
  20.  
  21. #pragma segment Core
  22.  
  23.  
  24. // System Includes
  25.  
  26. #ifndef __MEMORY__
  27.     #include <Memory.h>
  28. #endif
  29.  
  30. #ifndef __APPLEEVENTS__
  31.     #include <AppleEvents.h>
  32. #endif
  33.  
  34. #ifndef __DIALOGS__
  35.     #include <Dialogs.h>
  36. #endif
  37.  
  38. #ifndef __DESK__
  39.     #include <Desk.h>
  40. #endif
  41.  
  42. #ifndef __WINDOWS__
  43.     #include <Windows.h>
  44. #endif
  45.  
  46.  
  47.  
  48.  
  49. // Application includes
  50.  
  51. #ifndef __BAREBONES__
  52.     #include "BareBones.h"
  53. #endif
  54.  
  55. #ifndef __PROTOTYPES__
  56.     #include "Prototypes.h"
  57. #endif
  58.  
  59.  
  60.  
  61.  
  62. // static includes
  63.  
  64. static void DoMouseDown ( EventRecord* theEvent );
  65. static void DoKey ( EventRecord*theEvent );
  66.  
  67.  
  68.  
  69. void EventLoop ( void )
  70. {
  71.     OSErr            theErr;
  72.     EventRecord        theEvent;
  73.     
  74.     
  75.     while ( !gQuit )
  76.     {
  77.         WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );    
  78.         
  79.         switch ( theEvent.what )
  80.         {
  81.             case mouseDown: 
  82.                 DoMouseDown ( &theEvent );
  83.             break;
  84.             
  85.             case keyDown:
  86.             case autoKey: 
  87.                 DoKey ( &theEvent );
  88.             break;
  89.             
  90.             case activateEvt: 
  91.                 DoActivate ( &theEvent );
  92.             break;
  93.             
  94.             case updateEvt:
  95.                 DoUpdate ( &theEvent );
  96.             break;
  97.             
  98.             case osEvt:
  99.                 if ( (theEvent.message >> 24) & suspendResumeMessage )    // suspend or resume
  100.                 {
  101.                     // Modify the event record to look like an activate/deactivate event
  102.                     theEvent.modifiers = theEvent.message;        // Copy suspend/resume flag
  103.                     theEvent.message = (long) FrontWindow ( );    
  104.  
  105.                     (void)RemoveNotification( );    // Removes notification if there is one
  106.  
  107.                     DoActivate ( &theEvent );
  108.                 }
  109.             break;
  110.             
  111.             case kHighLevelEvent:
  112.                 theErr = AEProcessAppleEvent ( &theEvent );
  113.             break;
  114.         }
  115.     }
  116.     
  117.     return;
  118.     
  119. } // EventLoop
  120.  
  121.  
  122.  
  123. static void DoMouseDown ( EventRecord* theEvent )
  124. {
  125.     Point            globalPt = theEvent->where;
  126.     SInt16            windowPart;
  127.     WindowRef        theWindow;
  128.     long            theMenu;
  129.     
  130.     
  131.     windowPart = FindWindow ( globalPt, &theWindow );
  132.     switch ( windowPart )
  133.     {
  134.         case inMenuBar: 
  135.             theMenu = MenuSelect ( globalPt );
  136.             MenuDispatch ( theMenu );
  137.         break;
  138.         
  139.         case inSysWindow:
  140.             // The SystemClick toolbox routine handles system events
  141.             SystemClick ( theEvent, theWindow );
  142.         break;
  143.         
  144.         case inGoAway:
  145.             // We'll quit when the user closes the window
  146.             if ( TrackGoAway ( theWindow, theEvent->where ) )
  147.                 gQuit = true;
  148.         break;
  149.         
  150.         case inDrag:
  151.             DoDragWindow ( theWindow, theEvent );
  152.         break;
  153.  
  154.         case inContent:
  155.             DoContentClick ( theWindow, theEvent );
  156.         break;
  157.     }
  158.     
  159.     return;
  160.     
  161. } // DoMouseDown
  162.  
  163.  
  164.  
  165. static void DoKey ( EventRecord* theEvent )
  166. {
  167.     char keyPressed = (theEvent->message & charCodeMask);
  168.     
  169.     
  170.     // Command keys get handled by the menu handling routines
  171.     if ( theEvent->modifiers & cmdKey )
  172.         MenuDispatch ( MenuKey ( keyPressed ) );
  173.     
  174.     return;
  175.     
  176. } // DoKey
  177.  
  178.  
  179.  
  180.  
  181.